package com.java.base.javabase.thread;

import com.java.base.javabase.thread.start.CallableStart;
import com.java.base.javabase.thread.start.RunnableStart;
import com.java.base.javabase.thread.start.ThreadStart;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 *@ClassName ThreadMainTest
 *@Description TODO https://segmentfault.com/a/1190000020287859?utm_source=sf-related
 *@Author FangShanShan
 *@Date 2020/8/9 20:45
 *@Version 1.0
 */
@Slf4j
public class ThreadMainDemo {

    public static void main(String[] args) {
        log.info("### 我是主线程标志：[{}]", Thread.currentThread().getName());


        threadMoreStart();
        // callableStart();
        //runableMoreStart();
        // threadMoreStart();
        //runnableStart(); // Runnable启动
        //threadStart(); // Thread启动
    }

    private static void callableStart() {
        FutureTask<List<String>> futureTask = new FutureTask<>(new CallableStart());
        Thread thread = new Thread(futureTask);
        thread.setName("我是线程");
        thread.start();
    }

    private static void runableMoreStart() {
        for(int i = 0; i < 10; i++) {
            new Thread(new RunnableStart()).start();
        }
    }

    private static void threadMoreStart() {
        List<Thread> threadList = new ArrayList<>();
        Thread thread = null;
        for(int i = 0; i < 10; i++) {
            thread = new ThreadStart();
            thread.setName("线程"+ i);
            threadList.add(thread);
        }
        for(Thread temp : threadList) {
            temp.start();
        }

        /*Thread thread = null;
        for(int i = 0; i < 10; i++) {
             thread = new ThreadStart();
             thread.start();
        }*/

    }

    /**
     *@Author FangShanShan
     *@Description TODO Runnable启动
     *@Date 2020/8/10 21:36
     *@Return
     */
    private static void runnableStart() {
        Thread thread = new Thread(new RunnableStart());
        thread.run();
        thread.start();
    }

    /**
     *@Author FangShanShan
     *@Description TODO Thread 启动
     *@Date 2020/8/10 21:35
     *@Return
     */
    private static void threadStart() {
        ThreadStart threadStart  = new ThreadStart();
        threadStart.run();
        threadStart.start();
    }
}